package me.jiatao.wan.ui.main.home

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import me.jiatao.wan.data.network.HttpStatusResult
import me.jiatao.wan.data.network.pojo.BannerPojo
import me.jiatao.wan.data.repository.Repository
import me.jiatao.wan.model.ArticleModel
import javax.inject.Inject

/**
 * @Author: taojia
 * @CreateDate: 2021/8/25 10:47 上午
 * @Version: 1.0
 * @Description:
 */

@HiltViewModel
class HomeViewModel @Inject constructor(
    private val repository: Repository
) : ViewModel() {

    /**
     * 加载首页轮播图数据
     */
    val fetchBannerFlow: Flow<HttpStatusResult<List<BannerPojo>>> by lazy {
        repository.fetchBannerList()
    }

    /**
     * 加载首页文章数据
     */
    fun loadHomeArticleListVM(): LiveData<PagingData<ArticleModel>> =
        repository.fetchHomeArticleList().cachedIn(viewModelScope).asLiveData()
}